import os

"""A very simple file convertor.

说明如下：
一  处理步骤如下
1. 利用lzop命令行将lzo文件解压缩到文本文件
2. 通过读取文件，转为个字典插入到dataframe中
3. 将数据转化为csv数据类

"""

decompress_cmd = r'lzop -d '
data_directory = r'/home/bussanq/Desktop/pr/'
lzo_file = '.lzo'

cmd = decompress_cmd + data_directory + lzo_file


def decom_files(path, format_str):
    for root, dirs, files in os.walk(path):
        for name in files:
            if name.endswith(format_str):
                path = os.path.join(root, name)
                # print(path)
                # print(type(path))
                cmd = decompress_cmd + path
                os.system(cmd)
                # os.remove(os.path.join(root, name))

                print("decompress File: " + os.path.join(root, name))


def del_files(path, format_str):
    for root, dirs, files in os.walk(path):
        for name in files:
            if name.endswith(format_str):
                os.remove(os.path.join(root, name))
                print("Delete File: " + os.path.join(root, name))


if __name__ == "__main__":
    del_files(data_directory, '.writed')

    decom_files(data_directory, '.lzo')

    del_files(data_directory, '.lzo')
    print('删除完成')
